<template>
	<view class="reference-case">
		<common-navbar title="参考案例" />
		<view class="top-charge-bar">
			<view class="charge-info">
				<view class="charge-icon">
					{{chargename.charAt(0)}}
				</view>
				<view class="charge-name">
					{{chargename}}
				</view>
			</view>

			<view class="case-total">
				全部案例({{total}})
			</view>
		</view>
		<scroll-view scroll-y class="scroll-view" @scrolltolower="scrolltolower">
			<view class="case-item" v-for="item in caseList" :key="item.id" @click="$u.route(`/pages_recommended/case_detail/caseDetail?id=${item.id}`)">
				<view class="case-name">
					{{item.title}}
				</view>
				<view class="case-info">
					<view class="court-name">
						{{item.court}}
					</view>
					<view class="case-number">
					  {{item.reference_number}}
					</view>
				</view>
				<view class="analysis-title">
					法院分析
				</view>
				<view class="case-content">
					<!-- <u-parse :html="item.content" :show-with-animation="true" :lazy-load="true" style="margin-top: 4rpx;"></u-parse> -->
					{{item.content}}
				</view>
			</view>
			<u-loadmore :status="status" />
		</scroll-view>
		<vipPopup ref="vipPopup"/>
	</view>
</template>

<script>
	import vipPopup from "../components/vip-popup/vipPopup.vue";
	export default {
		components:{
			vipPopup,
		},
		data(){
			return {
				caseList:[],
				chargename:'',
				total:0,
				pageNum:1,
				pageSize:5,
				status:'loadmore',
				detailId:'',
			}
		},
		async onLoad(options){
			console.log(options)
			this.chargename = decodeURIComponent(options.chargename);
			this.detailId = options.id;
			await this.$loginStatus;
			this.getCaseList();
		},
		methods:{
			async getCaseList(id){
				if(this.status == 'loading'||this.status == 'nomore'){
					return
				}
				this.status = 'loading';
				try{
					const {data,total} =  (await this.$u.post(this.$restUrl.getCaseList,{
						binding_charge_id:this.detailId,
						page:this.pageNum,
						page_num:this.pageSize,
					})).data
					this.total = total;
					this.caseList.push(...data);
					console.clear()
					console.log('total>>>>>>>>',total);
					console.log('caseList.length',this.caseList.length);
					if(this.caseList.length>= total){
						this.status = 'nomore';
					}else{
						this.status = 'loadmore';
						this.pageNum++;
					}
					console.log('caseList>>>>>>>>>>',this.caseList);
				}catch(e){
					if(e.status_code == 404){
						this.$refs.vipPopup.show();
					}
					return
				}
			
			},
			scrolltolower(){
				console.log('scrolltolower')
				this.getCaseList();
			}
		}
	}
</script>

<style scoped lang="scss">
	@import "./referenceCase.scss";
</style>
